package com.example.redismanual.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisHashDao {
    
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public void hset(){
        stringRedisTemplate.opsForHash().put("article", "title", "article_title");
        stringRedisTemplate.opsForHash().put("article", "content", "I am article");
        stringRedisTemplate.opsForHash().put("article", "view_count", "100");
        stringRedisTemplate.opsForHash().get("article", "view_count");
        stringRedisTemplate.opsForHash().increment( "article", "view_count", 100);
        // HEXISTS：检查字段是否存在
        stringRedisTemplate.opsForHash().hasKey("article", "view_count");
        // HDEL：删除字段
        stringRedisTemplate.opsForHash().delete("article", "view_count");
        // HLEN：获取散列包含的字段数量
        stringRedisTemplate.opsForHash().size("article");

     }
}
